
/* C库 */
#include "stdio.h"
#include "string.h"

/* RTOS */
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/* 接口文件 */
#include "SpindleMotor.hpp"
#include "UniversalSerialPort.hpp"
#include "SpindleMotorService.hpp"

static TaskHandle_t spindle_motor_task;

static void SpindleMotorService_task(void *param){
    unsigned char receive[256];
    unsigned char data[5] = {1,2,3,4,5};

    SpindleMotor * spindle_motor = SpindleMotor::getInstance();
    bool  spindle_motor_ret = false;

    spindle_motor_ret = spindle_motor->enableMotor();
    printf("spindle_enableMotor:%s\r\n",spindle_motor_ret ? "True" : "False");
    
    spindle_motor_ret = spindle_motor->setSpeed(200);
    printf("spindle_setSpeed:%s\r\n",spindle_motor_ret ? "True" : "False");

    spindle_motor_ret = spindle_motor->corotationMotor();
    printf("spindle_corotationMotor:%s\r\n",spindle_motor_ret ? "True" : "False");

    vTaskDelay(8000);
    uint16_t speed = spindle_motor->getSpeed();
    printf("speed %d\r\n",speed);

    vTaskDelay(7000);
    spindle_motor_ret = spindle_motor->stopMotor();
    printf("spindle_stopMotor:%s\r\n",spindle_motor_ret ? "True" : "False");

    while(true){
        printf("spindle\r\n");
        vTaskDelay(2000);
        // int length = usart1->receive(receive);
        // if( length > 0){
        //     for( int i = 0; i < length; i ++){
        //         printf("%x\r\n",receive[i]);
        //     }
        // }

    }
}
bool SpindleMotorService::run(){
    xTaskCreate(SpindleMotorService_task,"spindle_control_task",256,nullptr,1,&spindle_motor_task);
    return true;
}